package github.flandre.examplemod.core.registry;

import github.flandre.examplemod.common.energy.item.FEDemoItem;
import github.flandre.examplemod.common.key.KeyBandinglist;
import github.flandre.examplemod.core.init.BlockInit;
import github.flandre.examplemod.core.init.ItemInit;
import github.flandre.examplemod.examplemod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.RenderTypeLookup;
import net.minecraft.data.ItemModelProvider;
import net.minecraft.item.ItemModelsProperties;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;

import java.util.Timer;
import java.util.TimerTask;

//材质仅在客户端渲染  FMLClientSetupEvent具有唯一性
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)//仅在客户端中体现
public class PropertyRegistry {
    @SubscribeEvent
    public static void propertyOverrideRegistry(FMLClientSetupEvent event){
        //客户端准备好事件
        //开启一个线程进行处理
        event.enqueueWork(()->{
            //物品 资源定位 判断
            ItemModelsProperties.registerProperty(ItemInit.MAGIC_BOARD.get(),
                    new ResourceLocation(examplemod.MODID, "size"), (itemStack, clientWorld, livingEntity) -> itemStack.getCount());
        });

        event.enqueueWork(()->{
            ItemModelsProperties.registerProperty(ItemInit.FE_DEMO_ITEM_REGISTRY.get(),
                    new ResourceLocation("energy"), (itemStack, world, entity) ->
            {
                LazyOptional<IEnergyStorage> capability = itemStack.getCapability(CapabilityEnergy.ENERGY);
                return capability.map(e -> (float) e.getEnergyStored() / e.getMaxEnergyStored()).orElse(0.0F);
            });

        });



        event.enqueueWork(()->
        {
            RenderTypeLookup.setRenderLayer(BlockInit.EXAMPLE_LOG.get(), RenderType.getCutout());
            RenderTypeLookup.setRenderLayer(BlockInit.EXAMPLE_SAPLING.get(), RenderType.getCutout());
        });




        //键位
        KeyBandinglist.register(event);

    }


}


//单人游戏 -> 客户端 -> 创建世界 -> 开了一个服务器 -> 逻辑服务器 , 逻辑客户端
//mincraft - > mincraft-1.12.2xx.jar -> 物理客户端 -> 逻辑服务器 -> 逻辑客户端

//多人游戏 -> 远程服务器 minecraft-server-12.2.2xx.ar -> 物理服务端 -> 逻辑服务器
//物理客户端 -> 开启逻辑客户端
